<template>
  <div class="homepage">
    <v-search
      v-if="categorylist.length && categorylist.length > 0"
      @showSwitch="getisActive"
      @showType="getPatientType"
      :categorylist="categorylist"
      ref="vSearchel"
    ></v-search>
    <bed-card
      v-if="allpatientinfo.length && categorylist.length > 0 && isActive == 1"
      :allpatientinfo="allpatientinfo"
    ></bed-card>
    <bed-table
      v-if="allpatientinfo.length && categorylist.length > 0 && isActive == 2"
      :allpatientinfo="allpatientinfo"
    ></bed-table>
    <v-pagination :total="total" @currentPage="currentPage"></v-pagination>
  </div>
</template>

<script>
// 引入搜索框
import vSearch from "./search";
// 引入床位列表----卡片
import bedCard from "./bedCard";
// 引入床位列表----表格
import bedTable from "./bedTable";
// 引入分页组件
import vPagination from "../../components/pagination/index";

export default {
  data() {
    return {
      isActive: 1, //1为卡片显示 2为列表显示
      patientType: "",
      categorylist: [], //所有类别（全部人数,异常数据等）
      allpatientinfo: [], //所有患者列表
      routeID: "",
      total: 10,
      page: 1,
    };
  },
  mounted() {
    
    let routeid = sessionStorage.getItem("routeID");
    this.routeID = routeid ? JSON.parse(routeid)["/index"] : "";
    let data = {};
    this.getIndexUserInfo(data);
  },
  methods: {
    // 控制显示床位列表的类型
    getisActive(val) {
      this.isActive = val;
      this.page = 1;
    },
    // 获取指定状态的患者
    getPatientType(val) {},
    // 查询指定床位信息
    getBedInformation(data) {},
    //所有类别（全部人数,异常数据等） && 每个床位的详细信息
    getIndexUserInfo(value) {
      let userInfo = sessionStorage.getItem("userInfo");
      let currentLoginUserId = userInfo ? JSON.parse(userInfo) : {};
      let patientType = sessionStorage.getItem("patientType");
      let data = {
        currentLoginUserId: currentLoginUserId.id,
        dataType: patientType ? patientType : 0,
        currentClickPerId: this.routeID,
        size: 10, //当前页显示几条数据
        bedNum: value.bedNum, //床位号
        departmentId: value.departmentId, //科室
        diabetesType: value.diabetesType, //糖尿病类型
        hospitalNum: value.hospitalNum, //住院号
        patientName: value.patientName, //患者名称
        startTime: value.startTime, //起始时间
        endTime: value.endTime, //结束时间
        doctorId: value.doctorId, //医生
        current: this.page,
      };
      this.$api
        .getIndexUserInfo(data)
        .then((res) => {
          //所有类别

          this.categorylist = res.data.numData;
          // 床位详细信息 allpatientinfo
          this.allpatientinfo = res.data.data;
          // 总条数
          this.total = res.total;
        })
        .catch((err) => {
          this.allpatientinfo = [];
          this.total = 10;
        });
    },
    // 当前页码
    currentPage(page) {
      this.page = page;
      this.$refs.vSearchel.Inquiry();
    },
  },
  components: {
    vSearch,
    bedCard,
    bedTable,
    vPagination,
  },
  beforeDestroy() {
    // 销毁缓存存储的对应类型的患者
    sessionStorage.removeItem("patientType");
    // 销毁缓存存储的渲染格式得标志
    sessionStorage.removeItem("switchVal");
  },
};
</script>

<style lang="scss" scoped>
.homepage {
  // padding: 10px;
}
</style>